home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmlyac / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-03  |  7.0 KB  |  350 lines  |  [TEXT/R*ch]

  1. #include <assert.h>
  2. #include <ctype.h>
  3. #include <stdio.h>
  4. #ifdef ANSI
  5. #include <stdlib.h>
  6. #endif
  7.  
  8. #ifdef macintosh
  9. #include <CursorCtl.h>
  10. #endif
  11.  
  12. #if defined(THINK_C) || defined(__MWERKS__)
  13. #include "m.h"
  14. #include "s.h"
  15. #include <stdlib.h>
  16. #undef macintosh
  17. #define NO_UNIX
  18. #define outline outline_
  19. #define ANSI
  20. #else
  21. #ifdef macintosh
  22. #include ":::config:m.h"
  23. #include ":::config:s.h"
  24. #else
  25. #include "../config/m.h"
  26. #include "../config/s.h"
  27. #endif
  28. #endif
  29.  
  30. #ifdef MSDOS
  31. #define NO_UNIX
  32. #endif
  33. #ifdef macintosh
  34. #define NO_UNIX
  35. #endif
  36.  
  37. /*  machine-dependent definitions            */
  38. /*  the following definitions are for the Tahoe        */
  39. /*  they might have to be changed for other machines    */
  40.  
  41. /*  MAXCHAR is the largest unsigned character value    */
  42. /*  MAXSHORT is the largest value of a C short        */
  43. /*  MINSHORT is the most negative value of a C short    */
  44. /*  MAXTABLE is the maximum table size            */
  45. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  46. /*  WORDSIZE computes the number of words needed to    */
  47. /*    store n bits                    */
  48. /*  BIT returns the value of the n-th bit starting    */
  49. /*    from r (0-indexed)                */
  50. /*  SETBIT sets the n-th bit starting from r        */
  51.  
  52. #define    MAXCHAR        255
  53. #define    MAXSHORT    32767
  54. #define MINSHORT    -32768
  55. #define MAXTABLE    32500
  56.  
  57. #ifdef SIXTEEN
  58. #define BITS_PER_WORD    16
  59. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  60. #define    BIT(r, n)    ((((r)[(n)>>4])>>((n)&15))&1)
  61. #define    SETBIT(r, n)    ((r)[(n)>>4]|=((unsigned)1<<((n)&15)))
  62. #else
  63. #define BITS_PER_WORD    32
  64. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  65. #define    BIT(r, n)    ((((r)[(n)>>5])>>((n)&31))&1)
  66. #define    SETBIT(r, n)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  67. #endif
  68.  
  69. /*  character names  */
  70.  
  71. #define    NUL        '\0'    /*  the null character  */
  72. #define    NEWLINE        '\n'    /*  line feed  */
  73. #define    SP        ' '     /*  space  */
  74. #define    BS        '\b'    /*  backspace  */
  75. #define    HT        '\t'    /*  horizontal tab  */
  76. #define    VT        '\013'  /*  vertical tab  */
  77. #define    CR        '\r'    /*  carriage return  */
  78. #define    FF        '\f'    /*  form feed  */
  79. #define    QUOTE        '\''    /*  single quote  */
  80. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  81. #define    BACKSLASH    '\\'    /*  backslash  */
  82.  
  83.  
  84. /* defines for constructing filenames */
  85.  
  86. #ifndef MSDOS
  87. #define CODE_SUFFIX    ".code.c"
  88. #define    DEFINES_SUFFIX    ".tab.h"
  89. #define OUTPUT_SUFFIX   ".sml"
  90. #define    VERBOSE_SUFFIX    ".output"
  91. #define INTERFACE_SUFFIX ".sig"
  92. #else
  93. #define CODE_SUFFIX    ".cod"
  94. #define    DEFINES_SUFFIX    ".h"
  95. #define OUTPUT_SUFFIX   ".sml"
  96. #define    VERBOSE_SUFFIX    ".out"
  97. #define INTERFACE_SUFFIX ".sig"
  98. #endif
  99.  
  100. /* keyword codes */
  101.  
  102. #define TOKEN 0
  103. #define LEFT 1
  104. #define RIGHT 2
  105. #define NONASSOC 3
  106. #define MARK 4
  107. #define TEXT 5
  108. #define TYPE 6
  109. #define START 7
  110. #define UNION 8
  111. #define IDENT 9
  112.  
  113. /*  symbol classes  */
  114.  
  115. #define UNKNOWN 0
  116. #define TERM 1
  117. #define NONTERM 2
  118.  
  119.  
  120. /*  the undefined value  */
  121.  
  122. #define UNDEFINED (-1)
  123.  
  124.  
  125. /*  action codes  */
  126.  
  127. #define SHIFT 1
  128. #define REDUCE 2
  129.  
  130.  
  131. /*  character macros  */
  132.  
  133. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  134. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  135. #define    NUMERIC_VALUE(c)    ((c) - '0')
  136.  
  137.  
  138. /*  symbol macros  */
  139.  
  140. #define ISTOKEN(s)    ((s) < start_symbol)
  141. #define ISVAR(s)    ((s) >= start_symbol)
  142.  
  143.  
  144. /*  storage allocation macros  */
  145.  
  146. #define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  147. #ifdef macintosh
  148. #define FREE(x)         (SpinCursor ((short) 1), free((char*)(x)))
  149. #else
  150. #define    FREE(x)        (free((char*)(x)))
  151. #endif
  152. #define MALLOC(n)    (malloc((unsigned)(n)))
  153. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  154. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  155. #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
  156.  
  157.  
  158. /*  the structure of a symbol table entry  */
  159.  
  160. typedef struct bucket bucket;
  161. struct bucket
  162. {
  163.     struct bucket *link;
  164.     struct bucket *next;
  165.     char *name;
  166.     char *tag;
  167.     short value;
  168.     short index;
  169.     short prec;
  170.     char class;
  171.     char assoc;
  172.     char entry;
  173.     char true_token;
  174. };
  175.  
  176. /* TABLE_SIZE is the number of entries in the symbol table. */
  177. /* TABLE_SIZE must be a power of two.                */
  178.  
  179. #define    TABLE_SIZE 1024
  180.  
  181. /*  the structure of the LR(0) state machine  */
  182.  
  183. typedef struct core core;
  184. struct core
  185. {
  186.     struct core *next;
  187.     struct core *link;
  188.     short number;
  189.     short accessing_symbol;
  190.     short nitems;
  191.     short items[1];
  192. };
  193.  
  194.  
  195. /*  the structure used to record shifts  */
  196.  
  197. typedef struct shifts shifts;
  198. struct shifts
  199. {
  200.     struct shifts *next;
  201.     short number;
  202.     short nshifts;
  203.     short shift[1];
  204. };
  205.  
  206.  
  207. /*  the structure used to store reductions  */
  208.  
  209. typedef struct reductions reductions;
  210. struct reductions
  211. {
  212.     struct reductions *next;
  213.     short number;
  214.     short nreds;
  215.     short rules[1];
  216. };
  217.  
  218.  
  219. /*  the structure used to represent parser actions  */
  220.  
  221. typedef struct action action;
  222. struct action
  223. {
  224.     struct action *next;
  225.     short symbol;
  226.     short number;
  227.     short prec;
  228.     char action_code;
  229.     char assoc;
  230.     char suppressed;
  231. };
  232.  
  233.  
  234. /* global variables */
  235.  
  236. extern char dflag;
  237. extern char lflag;
  238. extern char rflag;
  239. extern char tflag;
  240. extern char vflag;
  241. extern char big_endian;
  242.  
  243. extern char *myname;
  244. extern char *cptr;
  245. extern char *line;
  246. extern int lineno;
  247. extern int outline;
  248.  
  249. extern char *action_file_name;
  250. extern char *entry_file_name;
  251. extern char *code_file_name;
  252. extern char *defines_file_name;
  253. extern char *input_file_name;
  254. extern char *output_file_name;
  255. extern char *text_file_name;
  256. extern char *union_file_name;
  257. extern char *verbose_file_name;
  258. extern char *interface_file_name;
  259.  
  260. extern FILE *action_file;
  261. extern FILE *entry_file;
  262. extern FILE *code_file;
  263. extern FILE *defines_file;
  264. extern FILE *input_file;
  265. extern FILE *output_file;
  266. extern FILE *text_file;
  267. extern FILE *union_file;
  268. extern FILE *verbose_file;
  269. extern FILE *interface_file;
  270.  
  271. extern int nitems;
  272. extern int nrules;
  273. extern int ntotalrules;
  274. extern int nsyms;
  275. extern int ntokens;
  276. extern int nvars;
  277. extern int ntags;
  278.  
  279. extern char unionized;
  280. extern char line_format[];
  281.  
  282. extern int   start_symbol;
  283. extern char  **symbol_name;
  284. extern short *symbol_value;
  285. extern short *symbol_prec;
  286. extern char  *symbol_assoc;
  287. extern char  **symbol_tag;
  288. extern char  *symbol_true_token;
  289.  
  290. extern short *ritem;
  291. extern short *rlhs;
  292. extern short *rrhs;
  293. extern short *rprec;
  294. extern char  *rassoc;
  295.  
  296. extern short **derives;
  297. extern char *nullable;
  298.  
  299. extern bucket *first_symbol;
  300. extern bucket *last_symbol;
  301.  
  302. extern int nstates;
  303. extern core *first_state;
  304. extern shifts *first_shift;
  305. extern reductions *first_reduction;
  306. extern short *accessing_symbol;
  307. extern core **state_table;
  308. extern shifts **shift_table;
  309. extern reductions **reduction_table;
  310. extern unsigned *LA;
  311. extern short *LAruleno;
  312. extern short *lookaheads;
  313. extern short *goto_map;
  314. extern short *from_state;
  315. extern short *to_state;
  316.  
  317. extern action **parser;
  318. extern int SRtotal;
  319. extern int RRtotal;
  320. extern short *SRconflicts;
  321. extern short *RRconflicts;
  322. extern short *defred;
  323. extern short *rules_used;
  324. extern short nunused;
  325. extern short final_state;
  326.  
  327. /* global functions */
  328.  
  329. extern char *allocate();
  330. extern bucket *lookup();
  331. extern bucket *make_bucket();
  332.  
  333.  
  334. /* system variables */
  335.  
  336. extern int errno;
  337.  
  338.  
  339. /* system functions */
  340.  
  341. #ifndef ANSI
  342.  
  343. extern void free();
  344. extern char *calloc();
  345. extern char *malloc();
  346. extern char *realloc();
  347. extern char *strcpy();
  348.  
  349. #endif
  350.